package Question;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2021-12-14
 * Time:20:49
 */
public class Problem {

    private Question[] questionsList;//题目清单
    private int[] usage = new int[10];

    //构造方法
    public Problem(String path,int size) throws FileNotFoundException {
        questionsList = new Question[10];
        File file = new File(path);
        Scanner scanner = new Scanner(file);
        try {
            for (int i = 0; i < 10; i++) {
                scanner.useDelimiter("[、\n]");
                int number = Integer.valueOf(scanner.next());
                String q = scanner.nextLine().substring(1);
                String[] choice = new String[size];
                for (int j = 0; j < size; j++) {
                    choice[j] = scanner.nextLine();
                }
                scanner.useDelimiter("答案：");
                String answer = scanner.nextLine().substring(3);
                questionsList[i] = new Question(number,q,choice,answer);
            }
        }catch (Exception exp){
            System.out.println(exp);
        }

    }

    //获取问题列表
    public Question[] getS() {
        return questionsList;
    }
    //设置问题列表
    public void setQuestionsList(Question[] s) {
        this.questionsList = s;
    }

    public int getUsage(int num) {
        return usage[num];
    }

    public void setUsage(int num) {
        this.usage[num] = 1;
    }

    public Question getQuestion(int number) {
        return questionsList[number];
    }

    public void display() {
        for (Question q:questionsList) {
            System.out.println(q);
            System.out.println();
        }
    }
//    public Question question(int number);
//    public void display();

    public static void main(String[] args) throws FileNotFoundException {
        Problem[] problems = new Problem[3];
        problems[0] = new Problem("E:\\方秋慧\\JAVA程序设计\\单选.txt",4);
        problems[1] = new Problem("E:\\方秋慧\\JAVA程序设计\\多选.txt",4);
        problems[2] = new Problem("E:\\方秋慧\\JAVA程序设计\\判断.txt",2);

        for (int i = 0; i < 3; i++) {
            problems[i].display();
        }
    }

}